/*
 * Title:        CloudScheduler Toolkit
 * Description:  a Toolkit for Modeling and Simulation of Job Scheduling and Resource Provisioning in Cloud System
 * Licence:      GPL - http://www.gnu.org/copyleft/gpl.html
 * Author:       Fuhui Wu
 *
 * Copyright (c) 2013-2014, The National University of Defense Technology, China
 */

package org.nudt.jCloud.resourceManager;

import java.util.List;
import java.util.Map;

import org.nudt.jCloud.infrastructure.Cluster;
import org.nudt.jCloud.infrastructure.Host;
import org.nudt.jCloud.infrastructure.Slot;
import org.nudt.jCloud.simulation.SIMTag;
import org.nudt.jCloud.simulation.VirtSlot;
import org.nudt.jCloud.simulation.VirtSlotAlloc;

public class GeneralShareStateRM extends ShareStateRM{

	public GeneralShareStateRM(String name, Cluster cluster) {
		super(name, cluster);
	}

	@Override
	public void processResCommit(VirtSlotAlloc virtSlotAlloc) {
		Map<Host, List<VirtSlot>> virtSlotSet = virtSlotAlloc.getVirtSlotSet();
		for(Host host : virtSlotSet.keySet()){
			List<VirtSlot> virtSlotList = virtSlotSet.get(host);
			for(int i=0; i<virtSlotList.size(); ++i){
				Slot slot = host.provideSlot(virtSlotList.get(i).getSlotType());
				virtSlotList.get(i).setSlot(slot);
			}
		}
		sendNow(virtSlotAlloc.getFrwk().getUserBroker().getId(),
				SIMTag.RESOURCE_COMMIT_ACK, virtSlotAlloc);
	}

}
